##! @TODO: check selinux status is enforcing or permissive
##!        - if disabled, then return 1
##!        - if permissive, then retrun 0
##!        - if enforcing, then return 0
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => PASS; 1 => FAIL
function CheckSElinuxStatus()
{
    local SELINUX_STATUS=`getenforce  | tr A-Z a-z`
    case ${SELINUX_STATUS} in
        disabled) return 1;;
        permissive) return 0;;
        enforcing) return 0;;
        *) return 1;;
          
    esac

}

##! @TODO: set selinux enforcing, or permissive
##!        - check expected status is the same with actual status
##!        - if not, check expected 
##!        -- if disabled, then return 1
##!        -- if permissive, then setenforce 0
##!        -- if enforcing, then setenforce 1
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => PASS; 1 => FAIL
function SetSElinux()
{
    local EXP=$1
    local SELINUX_STATUS=`getenforce | tr A-Z a-z`
    local RC=1


    while true; do
      if [ "${EXP}" != "${SELINUX_STATUS}" ];then
        if [ "${EXP}" = "disabled" ];then
            RC=1
            break
        elif [ "${EXP}" = "enforcing" ];then
            setenforce 1
            RC=$?
            SELINUX_STATUS=`getenforce | tr A-Z a-z`
            continue
        elif [ "${EXP}" = "permissive" ];then
            setenforce 0
            RC=$?
            SELINUX_STATUS=`getenforce | tr A-Z a-z`
            continue
        else
            echo "$EXP is wrong"
            RC=1
            break
        fi
      else
        RC=0
        break
      fi

    done


    return $RC
}
